﻿using MvcEntity;
using System.Data.Entity;

namespace MvcApplication
{
    public class DemoDbContext : DbContext
    {
        public DemoDbContext() : base("name=DemoDbContext")
        {
        }

        public DbSet<DemoUser> DemoUser { get; set; }

        public DbSet<RoleInfo> RoleInfo { get; set; }

        public DbSet<OrderInfoTest> OrderInfoTest { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            var entityModel = modelBuilder.Entity<DemoUser>().ToTable("demo_user");
            entityModel.ToTable("demo_user").HasKey(x => x.Id);//指定主键
            entityModel.Property(p => p.Id).HasColumnName("id");
            entityModel.Property(p => p.UserName).HasColumnName("user_name");
            entityModel.Property(p => p.UserPassword).HasColumnName("user_password");
            entityModel.Property(p => p.UserPhone).HasColumnName("user_phone");
            entityModel.Property(p => p.LastDate).HasColumnName("last_date");
            entityModel.Property(p => p.CreateDate).HasColumnName("create_date");
            entityModel.Property(p => p.LoginAt).HasColumnName("login_at");

            var entityUserInfoModel = modelBuilder.Entity<RoleInfo>().ToTable("role_info");
            entityUserInfoModel.ToTable("role_info").HasKey(x => x.Id);//指定主键
            entityUserInfoModel.Property(p => p.Id).HasColumnName("id");
            entityUserInfoModel.Property(p => p.RoleName).HasColumnName("role_name");
            entityUserInfoModel.Property(p => p.RoleGroupName).HasColumnName("role_group_name");
            entityUserInfoModel.Property(p => p.RoleRemark).HasColumnName("role_remark");
            entityUserInfoModel.Property(p => p.CreateDate).HasColumnName("create_date");
            entityUserInfoModel.Property(p => p.EditDate).HasColumnName("edit_date");


            var demoOrder = modelBuilder.Entity<OrderInfoTest>().ToTable("demo_order");
            demoOrder.ToTable("demo_order").HasKey(x => x.Id);//指定主键
            demoOrder.Property(p => p.Id).HasColumnName("id");
            demoOrder.Property(p => p.OrderDate).HasColumnName("order_date");
            demoOrder.Property(p => p.Amount).HasColumnName("amount");


            base.OnModelCreating(modelBuilder);
        }

    }
}
